package com.gs.cd.service.feign.sso;


import com.gs.cd.service.feign.sso.vo.Group4UserVo;
import com.gs.cd.service.feign.sso.vo.LoginVo;
import com.gs.cd.service.feign.sso.vo.SSOResultGroup4User;
import com.gs.cd.service.feign.sso.vo.SSOResultUsers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * Created by hippo  2020/2/20
 * todo sso v3接口文档 https://sso-internal.gridsumdissector.com/help/api/v3/users-get/
 * 可以有默认配置，因为sso那边接口不是经常换
 *
 * @Description
 */
@Component
@FeignClient(url = "${auth.sso-url.root:'https://sso-internal.gridsumdissector.com/api/v2'}", name = "sso-client-gs")
public interface SSOClient {


    /**
     * 验证凭据并取得用户信息
     *
     * @param ticket
     * @return
     */
    @RequestMapping(path = "${auth.sso-url.validate:validate}", method = RequestMethod.GET)
    SSOResult validate(@RequestHeader("ticket") String ticket);

    /**
     * 获取用户信息
     *
     * @param ticket
     * @return
     */
    @RequestMapping(path = "${auth.sso-url.userinfo:userinfo}", method = RequestMethod.GET)
    SSOResultUserInfo userInfo(@RequestHeader("ticket") String ticket);

    /**
     * 退出登录
     */
    @RequestMapping(path = "${auth.sso-url.logout:logout}", method = RequestMethod.DELETE)
    SSOResult logout(@RequestHeader("ticket") String ticket);

    /**
     * 登入
     *
     * @return
     */
    @RequestMapping(path = "${auth.sso-url.login:login}", method = RequestMethod.POST, consumes = "application/json")
    SSOResult login(@RequestBody LoginVo loginVo);


    /********************* SSO v3 接口才有的****************************/
    /**
     * 获取全部账户信息
     *
     * @return
     */
    @RequestMapping(path = "${auth.sso-url.users}", method = RequestMethod.GET, consumes = "application/json")
    SSOResultUsers users(@RequestHeader("authentication") String authentication,
                         @RequestParam("page") Integer page,
                         @RequestParam("page_size") Integer pageSize,
                         @RequestHeader("nonce_str") String nonceStr);

    /**
     * 未知用途
     *
     * @param group4UserVo
     * @return
     */
    @Deprecated
    @RequestMapping(path = "${auth.sso-url.user-in-group}", method = RequestMethod.POST, consumes = "application/json")
    SSOResultGroup4User group4User(@RequestBody Group4UserVo group4UserVo);
}
